package com.yupi.springbootinit.statemachine.core;

import lombok.Data;

/**
 * 状态转换结果
 */
@Data
public class TransitionResult {
    
    /**
     * 转换是否成功
     */
    private boolean success;
    
    /**
     * 错误码
     */
    private String errorCode;
    
    /**
     * 错误信息
     */
    private String errorMessage;
    
    /**
     * 转换前状态
     */
    private State fromState;
    
    /**
     * 转换后状态
     */
    private State toState;
    
    /**
     * 触发事件
     */
    private Event event;
    
    /**
     * 转换耗时（毫秒）
     */
    private long duration;
    
    /**
     * 创建成功结果
     */
    public static TransitionResult success(State fromState, State toState, Event event, long duration) {
        TransitionResult result = new TransitionResult();
        result.setSuccess(true);
        result.setFromState(fromState);
        result.setToState(toState);
        result.setEvent(event);
        result.setDuration(duration);
        return result;
    }
    
    /**
     * 创建失败结果
     */
    public static TransitionResult failure(String errorCode, String errorMessage, State fromState, Event event) {
        TransitionResult result = new TransitionResult();
        result.setSuccess(false);
        result.setErrorCode(errorCode);
        result.setErrorMessage(errorMessage);
        result.setFromState(fromState);
        result.setEvent(event);
        return result;
    }
}